<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Location extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('m_location');
	}

	public function index(){
		redirect("Admin/location");				
	}

	public function update_location_process($param){
		if($this->input->post('btn_update_location') != ""){
			$this->load->library('form_validation');

			$this->form_validation->set_rules('location_name', 'Location Name', 'required');
			$this->form_validation->set_rules('location_latitude', 'Latitude', 'required|numeric');
			$this->form_validation->set_rules('location_longitude', 'Longitude', 'required|numeric');

			if ($this->form_validation->run() != FALSE){
				$data_loc['name'] = $this->input->post('location_name');
				$data_loc['latitude'] = $this->input->post('location_latitude');
				$data_loc['longitude'] = $this->input->post('location_longitude');
				$data_loc['id'] = $param;
				$cek = $this->m_location->update_location($data_loc);

				if($cek){
					$this->session->set_flashdata('message', "Updating Location Success");
					$this->session->set_flashdata('message_type', '1');	
				}else{
					$this->session->set_flashdata('message', "Updating Location Failed");
					$this->session->set_flashdata('message_type', '0');
				}
			}else{
				$this->session->set_flashdata('message', validation_errors());
				$this->session->set_flashdata('message_type', '0');
			}
			redirect("Admin/edit_location/$param");
		}else{
			redirect("Admin/location");		
		}
	}

	public function delete_location_process($param){
		if($this->input->post('btn_delete_location') != ""){
			$cek = $this->m_location->delete_location($param);
			if($cek){
				$this->session->set_flashdata('message', "Deleting Location Success");
				$this->session->set_flashdata('message_type', '1');	
			}else{
				$this->session->set_flashdata('message', "Deleting Location Failed");
				$this->session->set_flashdata('message_type', '0');
			}
			redirect("Admin/location");
		}else{
			redirect("Admin/location");			
		}
	}
}

/* End of file Location.php */
/* Location: ./application/controllers/Location.php */